
using System;
using System.Collections.Generic;
using System.Text;

using NUnit.Framework;


namespace GenTechDataModel.Tests
{

    /// <summary>
    /// Tests for samples in the GenTech spec.
    /// </summary>
    [TestFixture]
    public class GenTechSpec
    {
        /// <summary>
        /// Test the sample assertions on page 17.
        /// </summary>
        [Test]
        public void SampleAssertionsPage17()
        {
            GenTechPersona gSmith = new GenTechPersona("George Smith");
            GenTechEvent marriage = new GenTechEvent();
            GenTechAssertion a1 = new GenTechAssertion();   // gSmith, marriage, "Father of the Groom"
        }


        /// <summary>
        /// Test the sample characteristics on page 34 of the GenTech spec.
        /// </summary>
        [Test]
        public void CharacteristicPage34()
        {
            //ASSERTION
            //  (Type S3a)
            //  Subject1-Type = Persona
            //  Subject1-ID = Persona-ID
            //  Subject2-Type = Characteristic
            //  Subject2-ID = Characteristic-ID
            //  Value = ---
            //CHARACTERISTIC
            //  Characteristic-ID = Match ASSERTION Subject
            //CHARACTERISTIC-PART
            //  Characteristic-ID = Match CHARACTERISTIC
            //  Characteristic-Part-Name = Blacksmith
            //  Characteristic-Part-Type-ID = Match CHARACTERISTIC-PART-TYPE
            //CHARACTERISTIC-PART-TYPE
            //  Characteristic-Part-Type-Name = Occupation

            const string occupation = "Blacksmith";

            GenTechCharacteristic c = new GenTechCharacteristic();
            GenTechPersona p = new GenTechPersona("John Doe");

            GenTechAssertion a = new GenTechAssertion(p, c);

            GenTechCharacteristicPartType cpt = new GenTechCharacteristicPartType("Occupation");

            GenTechCharacteristicPart cp = new GenTechCharacteristicPart(c, occupation, cpt);

            GenTechCharacteristicPart[] parts = c.Parts;
            Assert.AreEqual(1, parts.Length, "Characteristic should have one part");

            Assert.AreSame(cp, parts[0], "Part #1 should match");
            Assert.AreEqual(occupation, parts[0].Name, "Characteristic name should match.");
        }


        /// <summary>
        /// Test the sample characteristics on page 35 of the GenTech spec.
        /// </summary>
        [Test]
        public void CharacteristicPage35()
        {
            //ASSERTION
            //  S3a
            //  Subject1-Type = Persona
            //  Subject1-ID = Persona-ID
            //  Subject2-Type = Characteristic
            //  Subject2-ID = Characteristic-ID
            //  Value = ---
            //CHARACTERISTIC
            //  Characteristic-ID = Match ASSERTION Subject
            //  A-D-None = Ascending
            //CHARACTERISTIC-PART
            //  Record 1
            //    Characteristic-ID = Match CHARACTERISTIC
            //    Characteristic-Part-Name = John
            //    Characteristic-Part-Type-ID = Match CHARACTERISTIC-PART-TYPE
            //    Sequence-Number = 1
            //  Record 2
            //    Characteristic-ID = Match CHARACTERISTIC
            //    Characteristic-Part-Name = Quincy
            //    Characteristic-Part-Type-ID = Match CHARACTERISTIC-PART-TYPE
            //    Sequence-Number = 2
            //  Record 3
            //    Characteristic-ID = Match CHARACTERISTIC
            //    Characteristic-Part-Name = Smith
            //    Characteristic-Part-Type-ID = Match CHARACTERISTIC-PART-TYPE
            //    Sequence-Number = 3
            //  Record 4
            //    Characteristic-ID = Match CHARACTERISTIC
            //    Characteristic-Part-Name = Esq.
            //    Characteristic-Part-Type-ID = Match CHARACTERISTIC-PART-TYPE
            //    Sequence-Number = 4
            //CHARACTERISTIC-PART-TYPE
            //  Record 1
            //    Characteristic-Part-Type-Name = Given Name
            //  Record 2
            //    Characteristic-Part-Type-Name = Given Name
            //  Record 3
            //    Characteristic-Part-Type-Name = Surname
            //  Record 4
            //    Characteristic-Part-Type-Name = Suffix

            GenTechCharacteristic c = new GenTechCharacteristic();
            GenTechPersona p = new GenTechPersona("John Q. Smith");

            GenTechAssertion a = new GenTechAssertion(p, c);

            // The spec has two part types for "Given Name", but that doesn't make sense to me, so I've
            // only created one.  If there is a rational reason why we'd want two, then this should be changed...
            GenTechCharacteristicPartType cpt1 = new GenTechCharacteristicPartType("Given Name");
            GenTechCharacteristicPartType cpt2 = new GenTechCharacteristicPartType("Surname");
            GenTechCharacteristicPartType cpt3 = new GenTechCharacteristicPartType("Suffix");

            // These are intentionally constructed out of order to test sorting...
            GenTechCharacteristicPart cp2 = new GenTechCharacteristicPart(c, "Quincy", cpt1, 2);
            GenTechCharacteristicPart cp1 = new GenTechCharacteristicPart(c, "John", cpt1, 1);
            GenTechCharacteristicPart cp3 = new GenTechCharacteristicPart(c, "Smith", cpt2, 3);
            GenTechCharacteristicPart cp4 = new GenTechCharacteristicPart(c, "Esq.", cpt3, 4);

            GenTechCharacteristicPart[] parts = c.Parts;
            Assert.AreEqual(4, parts.Length, "Characteristic should have four parts");

            Assert.AreSame(cp1, parts[0], "Part #1 should match");
            Assert.AreSame(cp2, parts[1], "Part #2 should match");
            Assert.AreSame(cp3, parts[2], "Part #3 should match");
            Assert.AreSame(cp4, parts[3], "Part #4 should match");
        }


        /// <summary>
        /// Test the sample event on page 37 of the GenTech spec.
        /// </summary>
        [Test]
        public void EventPage37()
        {
            //ASSERTION
            //  Subject1-Type = Persona
            //  Subject1-ID = Persona-ID
            //  Subject2-Type = Event
            //  Subject2-ID = Event-ID
            //  Value = Event-Type-Role-ID
            //EVENT
            //  Event-ID = Match ASSERTION Subject
            //  Event-Name = Wedding of John Smith and Mary Jones
            //EVENT-TYPE
            //  Event-Type-Name = Marriage
            //EVENT-TYPE-ROLE
            //  Event-Type-Role-ID= Match ASSERTION Value
            //  Event-Type-Role-Name = Groom

            GenTechPersona p = new GenTechPersona("John Doe");

            GenTechEventType et = new GenTechEventType("Marriage");
            GenTechEventTypeRole etr = new GenTechEventTypeRole("Groom");

            GenTechEvent e = new GenTechEvent("Wedding of John Smith and Mary Jones", et);  // TODO - need to add date and place

            GenTechEventRole er = new GenTechEventRole(e, etr);

            GenTechAssertion a = new GenTechAssertion(p, er);
            // TODO
        }
    }
}
